#ifndef GL_MAPPING_VIEW
#define GL_MAPPING_VIEW

class GLMappingView : public GLView
{
public:

	GLMappingView(Model * model, HINSTANCE hins, LPCTSTR name , HWND parent = NULL): 
	  GLView( model, hins,  name, parent )
	{

	}
	static void threadFunction(void* param)
	{
		((GLMappingView*)param)->renderFunction();
	}
	void renderFunction()
	{
		//EnableOpenGL();
		::wglMakeCurrent(hDC, hRC);	

		//Apply the Shader here
		
		//thread synchronize
		model->setUpdated(model->mappingView, true);
		model->cullingState = true ;
		EnterCriticalSection(&CriticalSection); 
		glewInit();
		//shader.load("D:\\workspace\\Brush\\glsl\\mcolor.vert", "D:\\workspace\\Brush\\glsl\\mcolor.frag");
		shader.load("D:\\workspace\\Brush\\glsl\\mcolor.vert", "D:\\workspace\\Brush\\glsl\\nearest.frag");
		shader.bind();
		//nearestShader.bind();
		LeaveCriticalSection(&CriticalSection);

		model->init();
		while(loopFlag)
		{
			::Sleep(1);   
			EnterCriticalSection(&CriticalSection);
			if (model->getUpdated(model->mappingView) == true)
			{
				model->setShader(&shader);
				model->draw_expand_result();
				//model->draw_culling_result();
				::SwapBuffers(hDC);
				model->setUpdated(model->mappingView, false);
			}
			LeaveCriticalSection(&CriticalSection);
			
		}
		::wglMakeCurrent(0, 0);
		::CloseHandle(threadHandle);
		
	}

private:
};

#endif